<?php
namespace app\admin\controller;
// use think\Db;
// use think\captcha\Captcha;
class Specificationsshop extends Come{
    public function specificationsshop(){
        $res=db('goods_type')->select();
        $this->assign('res',$res);
        return $this->fetch('specificationsshop');
    }
    public function index(){
        $data=input('param.','','htmlspecialchars');
        $data['vals']=explode("\r\n",$data['vals']);
        $data1='';
        $data1=[
            'name'=>$data['guige_name'],
            'type_id'=>$data['id_num'],
            'order_num'=>$data['pnum'],
        ];
        $ret=db('goods_format_name')->where('name',$data['guige_name'])->where('type_id',$data['id_num'])->find();
        if($ret!=NULL){
            $format_id=$ret['id'];
        }else{
            $format_id=db('goods_format_name')->insertGetId($data1);
        }
        foreach($data['vals'] as $val){
                $data2='';
                $data2=[
                    'format_id'=>$format_id,
                    'vals'=>$val,
                ];
                $ret2=db('goods_format_value')->insertGetId($data2);
            }
       
        
        if($ret2>0){
            $this->success('发布成功!','admin/specificationsshop/specificationsshop');
        }else{
            $this->error('发布失败');
        }
       
        
    }
}